package com.erp.wallet.controller;

import com.ruoyi.wallet.api.domain.ErpDistributionUserWallet;
import com.erp.wallet.service.IErpDistributionUserWalletService;
import com.ruoyi.common.core.web.oldController.BaseController;
import com.ruoyi.common.security.annotation.InnerAuth;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @Description: 用户钱包
 * @Author: j.zh
 * @Date: 2024/5/2
 * @Version: 4.0.0
**/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/distribution/wallet")
public class ErpDistributionUserWalletController extends BaseController {

	@Resource
	IErpDistributionUserWalletService distributionUserWalletService;

	@InnerAuth
	@GetMapping("/init/{distributionUserId}/{userId}")
	public ErpDistributionUserWallet initWallet(@PathVariable("distributionUserId") Long distributionUserId,
												@PathVariable("userId") Long userId) {
		ErpDistributionUserWallet userWallet = new ErpDistributionUserWallet();
		userWallet.setDistributionUserId(distributionUserId);
		userWallet.setUserId(userId);
		userWallet.setUnsettledAmount(new BigDecimal("0"));
		userWallet.setSettledAmount(new BigDecimal("0"));
		userWallet.setFreezeAmount(new BigDecimal("0"));
		userWallet.setInvalidAmount(new BigDecimal("0"));
		userWallet.setAccrueAmount(new BigDecimal("0"));
		userWallet.setEvaluateAmount(new BigDecimal("0"));

		return distributionUserWalletService.insert(userWallet);
	}

	@GetMapping("/getWalletByUserId/{userId}")
	public ErpDistributionUserWallet getWalletByUserId(@PathVariable("userId") Long userId) {
		return distributionUserWalletService.getByUserId(userId);
	}
}
